package org.softmed.rest.generation.refactoring.stored;

import java.io.File;
import java.util.List;

import org.softmed.rest.config.Resource;
import org.softmed.rest.generation.refactoring.ApplicationService;
import org.softmed.rest.generation.refactoring.ClassService;
import org.softmed.rest.generation.refactoring.FieldService;
import org.softmed.rest.generation.refactoring.ModuleService;

public class StoredDataCreator {

	public ApplicationServiceData getStoredData(ApplicationService service) {

		ApplicationServiceData data = new ApplicationServiceData();
		data.setDirectoryName(service.getDirectoryName());
		data.setId(service.getApplication().getId());

		// TODO
		List<ModuleService> mods = service.getModules();
		for (ModuleService moduleService : mods) {
			ModuleServiceData storedModuledata = getStoredData(moduleService);
			data.getModules().add(storedModuledata);
		}

		return data;

	}

	public ModuleServiceData getStoredData(ModuleService moduleService) {
		ModuleServiceData data = new ModuleServiceData();
		data.setDirectoryName(moduleService.getDirectoryName());
		data.setId(moduleService.getModule().getId());

		List<ClassService> classes = moduleService.getClasses();
		for (ClassService classService : classes) {
			ClassServiceData storedClassData = getStoredData(classService);
			data.getClasses().add(storedClassData);
		}

		return data;
	}

	private ClassServiceData getStoredData(ClassService classService) {
		ClassServiceData data = new ClassServiceData();
		data.setName(classService.getName());

		List<Resource> res = classService.getResources();
		for (Resource resource : res) {
			data.getResources().add(resource.getId());
		}

		List<FieldService> fields = classService.getFields();
		for (FieldService fieldService : fields) {
			FieldServiceData storedFieldData = getStoredData(fieldService);
			data.getFields().add(storedFieldData);
		}

		return data;
	}

	private FieldServiceData getStoredData(FieldService fieldService) {
		FieldServiceData data = new FieldServiceData();

		return data;
	}
}
